<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <lk-count></lk-count>
      <lk-count></lk-count>
      <lk-count></lk-count>
      <lk-count></lk-count>
    </div>

    <template id="count">
      <h2>结果:{{count}}</h2>
      <button @click="add">+</button>
      <button @click="sub">-</button>
      <hr>
    </template>

    <script src="../js/vue.js"></script>

    <script>
      //data为什么是函数,不是对象
      //因为函数每次调用都会开辟出一块新的内存空间,都会独立存在,不会影响其他的
      //若为对象的话,则所有的调用都指向同一块内存空间,就会相互影响
      const Count = {
        data() {
          return {
            count: 0,
          };
        },
        template: "#count",
        methods: {
          add(){
            this.count++
          },
          sub(){
            this.count--
          }
        }
      };


      const app = Vue.createApp({
        data() {
          return {
            msg: "213",
          }
        },
        components:{
          'lk-count':Count
        }
        
      });
      
      app.mount("#app");
    </script>
  </body>
</html>
